import logger from 'jet-logger';
import app from './server';
import ENV from '@src/common/constants/ENV';
import db from '@src/repos/MockOrm';
import dbInit from './repos/dbInit';

// 初始化数据库连接
async function initialize() {
  try {
    // 测试数据库连接
    await db.testConnection();

    // 初始化数据库表结构
    await dbInit.initDatabase();

    // 启动服务器
    const port = Number(ENV.Port) || 3000;
    app.listen(port, () => {
      console.log(`Server is running on port ${port}`);
    });
  } catch (error) {
    console.error('Initialization failed:', error);
  }
}

// 执行初始化
initialize().catch(logger.err);
